package com.bbx.taxi.client.UpdateChecker.ui;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import com.bbx.androidapi.util.ToastUtil;
import com.bbx.taxi.client.Activity.login.TransparentActivity;
import com.bbx.taxi.client.Bean.Value;
import com.bbx.taxi.client.Service.UpgradeService;
import com.bbx.taxi.client.Service.UpgradeService.OnUpdateProgressListener;
import com.bbx.taxi.official.R;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.RemoteViews;

/** 
 * @Path com.bbx.taxi.client.UpdateChecker.ui.MyUpdateLoad.java
 * @Author 严旭文
 * @Date 2016-4-27 下午5:00:54
 * @Company 蓝海（福建）信息技术有限公司
 * @Description
 */
public class MyUpdateLoad implements OnUpdateProgressListener{
	public enum UpdateType{
		TYPE_QIDONG,TYPE_SET
	}
	private Activity context;
	private File apkFile;
	private String apkUrl;
	private String pathSavedDir;
	private String apkName ;
	 MyUpdateDailog dialog;
	// 下载进度条
	private MyProgressBar progressBar;
	public void downloadApk(Activity context,boolean Forced,UpdateType noupdatetype,final String apkUrl,String versiton) {
		this.apkUrl=apkUrl;
		this.pathSavedDir=Value.APK_PATH;
		this.context=context;
		Intent intent = new Intent(context, UpgradeService.class);
		intent.putExtra(UpgradeService.INTENT_URL,apkUrl);
		intent.putExtra(UpgradeService.INTENT_VERSION,versiton);
		context.startService(intent);
		ToastUtil.showToast(context,R.string.downloading);
		if(Forced||noupdatetype==UpdateType.TYPE_SET){
			dialog=new MyUpdateDailog(context);
			dialog.show();
			if(Forced){
				dialog.setCancelable(false);
			}
		    progressBar=dialog.getProgressBar();
		    UpgradeService.setOnUpdateProgressListener(this);
		}
		
	}
	@Override
	public void onUpdateProgress(int progress) {
		progressBar.setProgress(progress);  
       if(progress>=100){
    	   if(dialog!=null)dialog.dismiss();
          }  
		
	}
	
}
